Fix: getChat & getChats & getChatModal & getChatById (clean solution)#201854
Closed
DnTora wants to merge 1 commit into
Closed
Fix: getChat & getChats & getChatModal & getChatById (clean solution)#201854DnTora wants to merge 1 commit into
DnTora wants to merge 1 commit into
Conversation
Squashed from 3 commits: initial fix, merge commit, and lint fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes an issue where getChat & getChats & getChatModal & getChatById could fail with a minified Puppeteer Evaluation failed error if a chat's lastReceivedKey did not contain a valid message identifier.
Root Cause
getChatModel() resolves lastMessage by reading the message referenced by lastReceivedKey.
When the message identifier is empty or undefined, the underlying IndexedDB lookup (IDBObjectStore.get()) throws a DataError, which propagates out of getChatModel() and causes getChats() / getChatById() to fail.
Changes
Validate that lastReceivedKey contains a valid message identifier before attempting the lookup.
Wrap the message lookup in try/catch.
Return lastMessage: null when the message cannot be resolved instead of throwing.
Result
No behavior changes for chats with valid lastReceivedKey values.
Chats with invalid or missing message identifiers no longer fail the entire request.
getChats() and getChatById() now return successfully, with lastMessage: null when appropriate.
Validation
✅ JavaScript syntax verified.
✅ Tested against a live WhatsApp session.
✅ getChats() and message retrieval now succeed for chats that previously caused the request to fail.